// pages/me/personal-data.js
var app = getApp();
var util = require('../../utils/util.js')
var _this;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //地址
    appLink: app.globalData.appLink, //app.globalData.appLink,
    // 链接判断
    buttonClicked: false,
    optionBox: false,
    userInfo: app.globalData.programUserInfo
  },
  onShareAppMessage: function () {

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    _this = this;
    _this.init();
  },
  init:function(){
    _this.setData({
      userInfo: app.globalData.programUserInfo
    })
    let data = {};
    data.userId = _this.data.userInfo.id;
    app.getMassage(data, null, 'getLpInfo', function(res){
      console.log(res);
      _this.setData({
        lpInfo: res.data
      })
    },'GET')
  },
  // 绑定电话
  getPhoneNumberFun: function (e) {
    var _this = this;
    var errMsg = e.detail.errMsg;
    var data = errMsg.indexOf('fail');
    if (data != -1) {
      console.log('失败')
    } else {
      // 判断是否有电话信息
      console.log('成功')
      console.log(app.globalData.programUserInfo);
      // 没有去获取电话信息
      var encryptedData = e.detail.encryptedData,
        iv = e.detail.iv,
        openid = app.globalData.programUserInfo.openid;
      console.log('xieyouInfo=', app.globalData.programUserInfo)
      app.getUserPhone(encryptedData, openid, iv, function (rs) {
        _this.setData({
          userInfo: app.globalData.programUserInfo
        })
      })
    }
  }
})